div.container
  h1 Settings
  h2 PiSwitch — RC-Switch for Raspberry Pi
  p  Connect your 433 MHz transmitter to a GPIO pin and control your power sockets from anywhere.
  p  GPIO pins need to be exported with <code>gpio export [pin] out</code> before usage.
  p  <small>By default, Broadcom pin numbering is used. PiSwitch <em>should</em> be fully compatible with RC-Switch for Arduino, i.e., the same devices should work.</small>
  - if (typeof(success) !== 'undefined')
    div.alert.alert-success.fade.in
      button.close(type="button", data-dismiss="alert") ×
      =success
  div.row16
    form(action="/settings/piswitch", method="post")
      div#piswitch
        each item, i in items
          div.plugin-container.piswitch.settings(id="#{item._id}")
            button.btn.btn-danger.pull-right.delete(type="button",data-delete="#{item._id}")
              i.icon-trash.icon-large
              |  Delete
            label(for="description") Description (optional):
            input(type="text", name="data[#{i}][description]", placeholder="Bedroom light", value="#{item.description}")
            label(for="pin") Raspberry Pi GPIO pin:
            input.uppercase(type="text", name="data[#{i}][pin]", placeholder="10", maxlength="2", required="1", value="#{item.pin}", pattern="^A[0-9]|[0-9]{2}$")

            div.switch
              label(for="rctype") RC code type:
              select(name="data[#{i}][rctype]")
                option(value="tristate", selected=(item.rctype != 'binary')) Tri-state
                option(value="binary",   selected=(item.rctype == 'binary')) Binary
              div.switch-container.no-clear-on-switch
                div.tristate(class=(item.rctype == 'binary' ? 'hidden' : ''))
                  label(for="code") Tri-state code (without suffix):
                  input.uppercase(type="text", name="data[#{i}][code]", placeholder="FF0F0FFF", data-required="1", maxlength="10", value=(item.code ? item.code : ''), pattern="^[A-Fa-f0-9]{8,10}$")
                  label(for="onsuffix") <code>on</code> suffix:
                  input.uppercase(type="text", name="data[#{i}][onsuffix]", placeholder="FF0F", data-required="1", maxlength="4", value=(item.onsuffix ? item.onsuffix : 'FF0F'), pattern="^[A-Fa-f0-9]{2,4}$")
                  label(for="offsuffix") <code>off</code> suffix:
                  input.uppercase(type="text", name="data[#{i}][offsuffix]", placeholder="FF00", data-required="1", maxlength="4", value=(item.offsuffix ? item.offsuffix : 'FF00'), pattern="^[A-Fa-f0-9]{2,4}$")
                div.binary(class=(item.rctype != 'binary' ? 'hidden' : ''))
                  label(for="binaryOn") Binary <code>on</code> code:
                  input(type="text", name="data[#{i}][binaryOn]", placeholder="", data-required="0", maxlength="24", value=(item.binaryOn ? item.binaryOn : ''), pattern="^[01]{24}$")
                  label(for="binaryOff") Binary <code>off</code> code:
                  input(type="text", name="data[#{i}][binaryOff]", placeholder="", data-required="0", maxlength="24", value=(item.binaryOff ? item.binaryOff : ''), pattern="^[01]{24}$")

            input(type="hidden", name="data[#{i}][_id]", value="#{item._id}")
            input(type="hidden", name="data[#{i}][status]", value="#{item.status}")
          
      p.piswitch.buttons
        button.btn.btn-info.add(data-target="piswitch", type="button", data-callback="registerSelectSwitch()") 
          i.icon-plus.icon-large
          |  Add
      
        button.btn.btn-success.save(type="submit") 
          i.icon-save.icon-large
          |  Save
          
input(type="hidden", name="iterator", id="iterator", value=(items.length))

div.plugin-container.piswitch.settings#template(style="display: none;")
  button.btn.btn-danger.pull-right.delete(type="button")
    i.icon-trash.icon-large
    |  Delete
  label(for="description") Description (optional):
  input(type="text", name="data[%i%][description]", placeholder="Bedroom light")
  label(for="pin") GPIO Pin:
  input.uppercase(type="text", name="data[%i%][pin]", placeholder="17", maxlength="2", required="1", pattern="^A[0-9]|[0-9]{2}$")

  div.switch
    label(for="rctype") Choose RC code type:
    select(name="data[%i%][rctype]")
      option(value="tristate",selected=true) Tri-state
      option(value="binary") Binary
    div.switch-container.no-clear-on-switch

      div.tristate
        label(for="code") Tri-state code (without suffix):
        input.uppercase(type="text", name="data[%i%][code]", maxlength="10", placeholder="FF0F0FFF", data-required="1", pattern="^[A-F0-9]{8,10}$")
        label(for="onsuffix") <code>on</code> suffix:
        input.uppercase(type="text", name="data[%i%][onsuffix]", maxlength="4", placeholder="FF0F", data-required="1", pattern="^[A-Fa-f0-9]{2,4}$")
        label(for="offsuffix") <code>off</code> suffix:
        input.uppercase(type="text", name="data[%i%][offsuffix]", maxlength="4", placeholder="FF00", data-required="1", pattern="^[A-Fa-f0-9]{2,4}$")

      div.binary.hidden
        p Enter the <code>on</code> and <code>off</code> codes separately as binary codes. Length is currently hardcoded at 24 bits, but this could be changed if the need arises.
        label(for="binaryOn") Binary <code>on</code> code:
        input(type="text", name="data[%i%][binaryOn]", placeholder="", data-required="0", maxlength="24", pattern="^[01]{24}$")
        label(for="binaryOff") Binary <code>off</code> code:
        input(type="text", name="data[%i%][binaryOff]", placeholder="", data-required="0", maxlength="24", pattern="^[01]{24}$")
      
    input(type="hidden", name="data[%i%][status]", value="0")
